<template>
    <div>
        <TopBackground :userInfo="userInfo">
            <template #topLeftBut>
                <van-button round size="small" icon="arrow-left" @click="$router.go(-1)" />
            </template>
        </TopBackground>
        <van-row 
            class="row"
            v-for="item in dynamic" 
            :key="item._id"
            @click="$router.push({ path: '/dynamic_detail', query: { dynamic_id: item._id } })"
        >
            <van-col class="col" span="5">
                <span>{{ getDate(item.time) }}</span>{{ getMonth(item.time) }}
            </van-col>
            <van-col class="col" span="8">
                <van-image width="50" height="50" fit="cover" 
                    v-for="(element, index) in item.imageUrls" 
                    :key="index" 
                    :src="element"
                />
            </van-col>
            <van-col class="col" span="11">{{ item.text }}</van-col>
        </van-row>
        <van-empty description="好像什么都没有" image="imges/custom-empty-image.png" v-if="dynamic.length <= 0" />
    </div>
</template>

<script>
    import TopBackground from "@/components/common/topBackground.vue";
    import { mapActions, mapMutations, mapState } from "vuex";

    export default {
        name: "OthersCircleView",
        components: {
            TopBackground,
        },
        computed: {
            ...mapState(['user', 'friendList']),
            ...mapState('userInfo',['dynamic', 'userInfo']),
        },
        methods: {
            ...mapMutations('userInfo', ['upDynamic', 'upUserInfo']),
            ...mapActions('userInfo', ['getDynamic']),
            getMonth(dateStr) {
                const date = new Date(dateStr);
                return (date.getMonth() + 1) + '月';
            },
            getDate(dateStr) {
                const date = new Date(dateStr);
                return date.getDate();
            }
        },
        async created() {
            if (this.$route.query?.user_id != undefined) {
                let res_dynamic = await this.getDynamic(this.$route.query?.user_id);

                this.upDynamic(res_dynamic.dynamicList);
                this.upUserInfo(res_dynamic.userInfo);
            }
        },
    };
</script>

<style lang="less" scoped>
    .van-button {
        position: fixed;
        top: 1.25rem;
        left: 1.25rem;
        z-index: 1;
    }
    .row {
        padding: 0px 10px 0 10px;
        margin-bottom: 20px; 
        box-sizing: border-box;
        .col {
            font-size: .8125rem;
            span {
                font-size: 1.5625rem;
            }
        }
    }
</style>
